package com.zhao.system.Controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhao.system.poro.Library;
import com.zhao.system.service.LibraryService;
import com.zhao.system.vo.Booksvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import response.Result;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaozhao
 * @since 2020-11-08
 */
@RestController
@CrossOrigin(allowCredentials ="true")
@Transactional
@RequestMapping("/library")
public class LibraryController {
    @Autowired
    LibraryService libraryService;

    //获取所有图书书室信息
    @RequestMapping("/getRoomName")
    public Result getRoomName(){
        List<Library> list = libraryService.list();
        return Result.ok().data("list",list);
    }
    //获取所有图书书室信息
    @RequestMapping("/getRoomNameById")
    public Result getRoomNamebyId(@RequestParam("id") Integer id){
        QueryWrapper<Library> wrapper=new QueryWrapper();
        wrapper.eq("rid",id);
        Library library = libraryService.getOne(wrapper);
        return Result.ok().data("lib",library);
    }
    //获取所有图书书室信息
    @RequestMapping("/updatebyId")
    public Result updatebyId(@RequestBody Booksvo booksvo){
        if(!booksvo.getValue1().contains("-")){
            System.out.println(booksvo.getValue1());
            return Result.ok().data("message","修改完成");
        }
        String[] split = booksvo.getValue1().split("-");
        System.out.println(split[0]);
        System.out.println(split[1]);
        Integer id = Integer.valueOf(split[0]);
        QueryWrapper<Library> wrapper=new QueryWrapper();
        wrapper.eq("rid",id);
        Library library=new Library();
        library.setName(split[1]);
        boolean b = libraryService.update(library, wrapper);
        if(b){
            System.out.println("11111111111111111111111");
        }
        return Result.ok().data("message","修改成功");
    }
}

